package com.wxy.controller;


import com.wxy.common.R;
import com.wxy.entity.Bill;
import com.wxy.entity.User;
import com.wxy.entity.vo.ConsumeVo;
import com.wxy.entity.vo.RefundVo;
import com.wxy.service.BillService;
import com.wxy.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tutu
 * @since 2022-11-07
 */
@Api(tags = "用户操作")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private BillService billService;

    //查询用户钱包余额
    @GetMapping("/{id}")
    public R getUserBalance(@PathVariable String id){
        User user = userService.getBalance(id);
        return R.ok().data("user", user);
    }

    //用户消费的接口
    @PostMapping("/consume")
    public R consume(@RequestBody ConsumeVo consumeVo){
        userService.consume(consumeVo);
        return R.ok();
    }

    //用户退款的接口
    @PostMapping("/refund")
    public R refund(@RequestBody RefundVo refundVo){
        userService.refund(refundVo);
        return R.ok();
    }

    //查询用户钱包金额变动明细的接口
    @GetMapping("/bills")
    public R getBills(){
        List<Bill> list = billService.list();
        return R.ok().data("bills", list);
    }



}

